package com.oauth2demo.comment;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * <h3>oauth2Demo</h3>
 * <p>全局处理器</p>
 *
 * @author gdw
 * @since 2024-07-04 15:50:52
 */
@ControllerAdvice(annotations = {RestController.class, Controller.class})//只要类上加了这两个处理器的就会被拦截
@ResponseBody
public class HandleOtherExceptions {
    @ExceptionHandler({RuntimeException.class})
    public R runtimeException(RuntimeException ex) {
        String message = ex.getMessage();
        return R.error(message);
    }
}
